package mutsumimod.actions.deprecated;

import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.powers.AbstractPower;
import mutsumimod.powers.BasePower;
import mutsumimod.powers.StandPower;

@Deprecated
public class PerfectStandAction extends AbstractGameAction {
    private final AbstractCreature target;
    private final int targetAmount;
    private final AbstractGameAction linkedAction;
    // 用于在不使用此行动时检查上次是否触发
    public static boolean latestTriggered = false;


    public PerfectStandAction(AbstractCreature target, int targetAmount, AbstractGameAction linkedAction) {
        this.target = target;
        this.targetAmount = targetAmount;
        this.linkedAction = linkedAction;
        this.duration = Settings.ACTION_DUR_FAST;
    }

    public PerfectStandAction(int targetAmount, AbstractGameAction linkedAction) {
        this(AbstractDungeon.player, targetAmount, linkedAction);
    }

    @Override
    public void update() {
        if (this.isDone) {
            return;
        }
        AbstractPower power = target.getPower(StandPower.POWER_ID);
        if ((power == null || power.amount != this.targetAmount)&&targetAmount!=0) {
            this.isDone = true;
            return;
        }
        PerfectStandAction.latestTriggered = true;
        for(AbstractPower p : AbstractDungeon.player.powers) {
            if(p instanceof BasePower){
                ((BasePower) p).onTriggerStand(power.amount,targetAmount);
            }
        }
        this.addToTop(this.linkedAction);
        this.isDone = true;
    }
}
